package com.monlyu.tag.extend;

import java.util.Map;

import com.google.common.collect.Maps;
import com.monlyu.tag.BaseTag;
import com.monlyu.util.FtlUtil;
import com.monlyu.util.StringUtil;
import com.monlyu.util.WebOptUtil;

/********************************************************************************
 * 
 * <b>功能描述☞</b>选择用户的时候的标签<br>
 * 
 * <b>开发公司☞</b>重庆唯尼科技有限公司<br>
 * <b>版权☞</b>本文件归重庆唯尼科技有限公司所有<br>
 * <b>项目名☞</b>NewsSys<br>
 * <b>文件路径☞</b>com.monlyu.tag.UserTag.java<br>
 * <b>开发日期☞</b>2010-2-28 <br>
 * 
 * @author monlyu
 * @since JDK 5
 * @version 1.0.8
 * 
 ********************************************************************************/
public class UserTag extends BaseTag {

	private String name;
	private boolean multiple = false;
	private String cssClass;
	private String value;
	private String th;

	public void setTh(String th) {
		this.th = th;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setMultiple(boolean multiple) {
		this.multiple = multiple;
	}

	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}

	@Override
	public int doStartTag() {
		try {
			write2Page(FtlUtil.render2Ftl(build(), "userTag.ftl"));
		} catch (Exception e) {
			name = cssClass = null;
		}
		return SKIP_BODY;
	}

	private Map<String, Object> build() {
		Map<String, Object> map = Maps.newHashMap();
		map.put("script", COMMON_SCRIPT_DIR);
		map.put("css", COMMON_CSS_DIR);
		map.put("sysname", WebOptUtil.APP_ARGS.getWebRelUrl());
		map.put("name", name);
		map.put("class", StringUtil.isTrimEmpty(cssClass) ? "" : cssClass);
		map.put("value", StringUtil.isTrimEmpty(value) ? "" : value);
		map.put("multiple", Boolean.toString(multiple));
		map.put("th", StringUtil.isTrimEmpty(th) ? "选择人员" : th);
		return map;
	}

}
